/**
 * 
 */
package com.wixc.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @author weichuanxi
 * @date 2016年4月13日
 */
public class ConstantsUtil {
	public static final int hotNews=0;
	public static final int chinaNews=1;
	public static final int foreignNews=2;
	public static final int finanNews=3;
	public static final int militaryNews=4;
	public static final int internetNews=5;
	public static final int scienceNews=6;
	public static final int socialNews=7;
	
	public static   String split=File.separator; //  \
	public static String path=System.getProperty("user.dir")+split+"WebRoot"+split;
	

	/**
	 * @param urlAll
	 *            :请求接口
	 * @param httpArg
	 *            :参数
	 * @return 返回结果
	 */
	public static String request(String apikey) {
	    BufferedReader reader = null;
	    String result = null;
	    StringBuffer sbf = new StringBuffer();

	    try {
	        URL url = new URL("http://apis.baidu.com/heweather/pro/weather?city=beijing");
	        HttpURLConnection connection = (HttpURLConnection) url
	                .openConnection();
	        connection.setRequestMethod("GET");
	        // 填入apikey到HTTP header
	        connection.setRequestProperty("apikey", apikey );
	        connection.connect();
	        InputStream is = connection.getInputStream();
	        reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
	        String strRead = null;
	        while ((strRead = reader.readLine()) != null) {
	            sbf.append(strRead);
	            sbf.append("\r\n");
	        }
	        reader.close();
	        result = sbf.toString();
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	    return result;
	}

	public static void main(String[] args) {
//		String jsonResult = request("43abbe1cf7f9842d0dd2919aa793f036");
//		System.out.println(jsonResult);
	}
}


